<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script text="javascript">
        var collection = {
            "1275": {
                "album": "依然范特西",
                "artist": "周杰伦",
                "tracks": [
                    "听妈妈的话",
                    "千里之外"
                ]
            },
            "2468": {
                "album": "西界",
                "artist": "林俊杰",
                "tracks": [
                    "西界",
                    "杀手"
                ]
            },
            "3245": {
                "artist": "许嵩",
                "tracks": []
            },
            "5439": {
                "album": "遇见"
            }
        }

            // 1.定义方法更新记录:
            // function updateRecords(id,prop,value)
            // 要求：
            // //1).如果传入的value是一个空值，表示将该属性删除
            // 2).传入的prop如果是tracks，则代表添加，其他是修改
            function updateRecords(id,prop,value){
            
            //   if(value == ''){
            //     delete collection[id][prop]
            //     console.log(collection[id]);
            //   }else{
            //      if(prop == 'tracks'){
            //     collection[id][prop].push(value)
            //     console.log(collection[id]);
            //   }else{
            //     collection[id][prop] = value;
            //     console.log(collection[id]);
            //   }
            //   }
               value == ''? delete collection[id][prop] :((prop == 'tracks')?collection[id][prop].push(value):collection[id][prop] = value)
               console.log(collection[id]);
            }
            
          

            // 3245 tracks '有何不可'
            updateRecords('3245','tracks','有何不可');
            // 3245 tracks ''   -->删
            updateRecords('3245','tracks','');
            // 5439 artist '孙燕姿'
            updateRecords('5439','artist','孙燕姿');
            // 5439 album '逆光'
            updateRecords('5439','album','逆光');
    </script>
</body>

</html>